#include "GLShaderConfig.h"

std::string GLShaderConfig::VERTEX_POSITION_TAG = "VertexPosition";
std::string GLShaderConfig::VERTEX_NORMAL_TAG = "VertexNormal";
std::string GLShaderConfig::VERTEX_DIFFUSE_TEXTURE_COORD_TAG = "DiffuseVertexTexCoord";
std::string GLShaderConfig::VERTEX_DIRT_TEXTURE_COORD_TAG = "DirtVertexTexCoord";

GLShaderConfig::GLShaderConfig() :
	attributesCount(0) {

}

GLShaderConfig::GLShaderConfig(std::string vertexShader, std::string fragmentShader) :
	vertexShader(vertexShader),
	fragmentShader(fragmentShader),
	attributesCount(0) {

}

GLShaderConfig::~GLShaderConfig() {
	attributesIndex.clear();
	attributesInfo.clear();
	attributesBuffer.clear();
}

GLShaderConfig::GLShaderConfig(const GLShaderConfig &config) {
	vertexShader = config.vertexShader.c_str();
	fragmentShader = config.fragmentShader.c_str();

	attributesIndex.insert(config.attributesIndex.begin(), config.attributesIndex.end());
	attributesInfo.insert(config.attributesInfo.begin(), config.attributesInfo.end());
	attributesBuffer.insert(config.attributesBuffer.begin(), config.attributesBuffer.end());
	attributesCount = config.attributesCount;
}

void GLShaderConfig::setShaderFiles(std::string vertexShader, std::string fragmentShader) {
	this->vertexShader = vertexShader;
	this->fragmentShader = fragmentShader;

}

void GLShaderConfig::addVertexAttrib(GLuint index, std::string attribName) {
	attributesIndex.insert(std::pair<std::string, int>(attribName, index));
}

void GLShaderConfig::addVertexAttribInfo(std::string attribName, VertexAttrib attrib, BufferConfig buffer) {
	GLuint index = attributesIndex[attribName];
	attrib.index = index;
	attributesInfo.insert(std::pair<std::string, VertexAttrib>(attribName, attrib));
	attributesBuffer.insert(std::pair<std::string, BufferConfig>(attribName, buffer));
	attributesCount++;
}

int GLShaderConfig::getVertexAttribIndex(std::string attribName) {
	if (attributesIndex.find(attribName) != attributesIndex.end()) {
		return attributesIndex[attribName];
	} else {
		return -1;
	}
}

VertexAttrib GLShaderConfig::getVertexAttribInfo(std::string attribName) {
	return attributesInfo[attribName];
}

BufferConfig GLShaderConfig::getVertexAttribBuffer(std::string attribName) {
	return attributesBuffer[attribName];
}
